home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
spoolaq.exe
/
SPOOLER.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1993-06-12
|
26KB
|
599 lines
(* █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█ *)
(* █ █ *)
(* █ S P O O L E R - Object █ *)
(* █ █ *)
(* ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ *)
unit Spooler;
{ F+}
{$O+} (* can be put in an overlay *)
interface
uses
DOS, Printer,
Objects, Views, Drivers, App;
(* ╔════════════════════════════════════════════════════════════════╗ *)
(* ║ ║ *)
(* ║ definition of exported constants ║ *)
(* ║ ║ *)
(* ╚════════════════════════════════════════════════════════════════╝ *)
const
Spool_LPT1 = 1;
Spool_LPT2 = 2;
Spool_COM1 = 1;
Spool_COM2 = 2;
Spool_COM3 = 3;
Spool_COM4 = 4;
Spool_300 = 0;
Spool_600 = 1;
Spool_1200 = 2;
Spool_2400 = 3;
Spool_4800 = 4;
Spool_9600 = 5;
Spool_Odd = 0;
Spool_Even = 1;
Spool_1Stop = 0;
Spool_2Stop = 1;
Spool_8Bit = 0;
Spool_7Bit = 1;
Spool_FlowXONXOFF = 0;
Spool_FlowDTR = 1;
(* ╔════════════════════════════════════════════════════════════════╗ *)
(* ║ ║ *)
(* ║ definition of object ║ *)
(* ║ ║ *)
(* ╚════════════════════════════════════════════════════════════════╝ *)
type
PSpooler = ^TSpooler;
TSpooler = object (TView )
constructor Init( Rect : TRect; NameOfFile : String );
destructor Done; virtual;
procedure SetParallel( PortNo : word ); virtual;
procedure SetSerial( PortNo,
BaudRate,
DataBits,
StopBits,
Parity,
FlowControl : word ); virtual;
procedure StartSpooling; virtual;
procedure StopSpooling; virtual;
procedure CancelSpooling; virtual;
procedure SpoolOneChar; virtual;
procedure Draw; virtual;
procedure Update; virtual;
procedure UseDOS( Flag : boolean ); virtual;
private
Active : boolean; (* spool-process is active *)
FileName : PString; (* name of file to output *)
SizeOfFile : longint; (* end-marker *)
Remainder : longint; (* no. of bytes to handle *)
NextChar : byte; (* the next char. for output *)
NextCharPtr : longint; (* Ptr. into file *)
IsParallel : boolean; (* to parallel/serial port ? *)
PortAddress : word; (* address of the port *)
SpoolFile : file; (* file for reading *)
lastTimerTicks : longint; (* needed for update of no. *)
FlowOfControl : word; (* which type of control ? *)
XOFF_Flag : boolean; (* XOFF sent ? *)
DirectHWAccess : boolean; (* use OUT-instr. or DOS-calls *)
procedure DeQueue;
function StatusLPT : boolean;
function COMGetc( COMx : word) : word;
function COMPutc(COMx:word; CommandChar:byte) : word;
function COMPutC_DTR(COMx:word; CommandChar:byte) : word;
end;
implementation
(* ╔════════════════════════════════════════════════════════════════╗ *)
(* ║ ║ *)
(* ║ definition of private constants ║ *)
(* ║ ║ *)
(* ╚════════════════════════════════════════════════════════════════╝ *)
const
XON = #$11;
XOFF = #$13;
(* ╔════════════════════════════════════════════════════════════════╗ *)
(* ║ ║ *)
(* ║ the Spooler-object ║ *)
(* ║ ║ *)
(* ╚════════════════════════════════════════════════════════════════╝ *)
(* ┌────────────────────────────────────────────────────────────────┐ *)
(* │ │ *)
(* │ construct the Spool-object │ *)
(* │ │ *)
(* └────────────────────────────────────────────────────────────────┘ *)
constructor TSpooler.Init( Rect : TRect; NameOfFile : String );
begin
TView.Init( Rect );
FileName := NewStr( NameOfFile );
Active := false;
NextCharPtr := 0;
NextChar := 0;
SizeOfFile := 0;
lastTimerTicks := 0;
IsParallel := true; (* default: parallel *)
PortAddress := MemW[$40:8]; (* = LPT1 *)
DirectHWAccess := true;
end;
(* ┌────────────────────────────────────────────────────────────────┐ *)
(* │ │ *)
(* │ remove Spool-object │ *)
(* │ │ *)
(* └────────────────────────────────────────────────────────────────┘ *)
destructor TSpooler.Done;
var
f : file;
begin
if Active then
CancelSpooling;
DisposeStr( FileName );
TView.Done;
end;
(* ┌────────────────────────────────────────────────────────────────┐ *)
(* │ │ *)
(* │ init of parallel interface │ *)
(* │ │ *)
(* └────────────────────────────────────────────────────────────────┘ *)
procedure TSpooler.SetParallel( PortNo : word );
begin
IsParallel := true;
PortAddress := MemW[$40:(3+PortNo) shl 1];
end;
(* ┌────────────────────────────────────────────────────────────────┐ *)
(* │ │ *)
(* │ init of serial interface │ *)
(* │ │ *)
(* └────────────────────────────────────────────────────────────────┘ *)
procedure TSpooler.SetSerial( PortNo,
BaudRate,
DataBits,
StopBits,
Parity,
FlowControl : word );
var
CommRegs : Registers;
begin
IsParallel := false;
PortAddress := MemW[$40:(PortNo-Spool_COM1) shl 1];
FlowOfControl := FlowControl;
XOFF_Flag := false; (* status = XON *)
with CommRegs do
begin
(* interpretation: look at BIOS, INT 14H, function 0 = init *)
AH := 0;
case BaudRate of
{ Spool_110 : AL := $00; }
{ Spool_150 : AL := $20; }
Spool_300 : AL := $40;
Spool_600 : AL := $60;
Spool_1200 : AL := $80;
Spool_2400 : AL := $A0;
Spool_4800 : AL := $C0;
Spool_9600 : AL := $E0;
end;
case Parity of
Spool_Odd : AL := AL or $08;
Spool_Even : AL := AL or $18;
end;
case StopBits of
Spool_1Stop : AL := AL or $00;
Spool_2Stop : AL := AL or $04;
end;
case DataBits of
Spool_8Bit